package com.zb.controller;


import com.zb.entity.dto.SmsTemplateDto;
import com.zb.entity.dto.SmsTemplateListSearchDto;
import com.zb.result.Result;
import com.zb.search.SearchDto;
import com.zb.service.ZjAdmSmsTemplateService;
import com.zb.utils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 后台短信模板表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2024-03-21
 */
@Api(tags = "短信模板类接口")
@RestController
@RequestMapping("/sms/template")
public class ZjAdmSmsTemplateController {
    @Resource
    private ZjAdmSmsTemplateService admSmsTemplateService;

    @ApiOperation("新增或修改短信模板")
    @PostMapping("/save")
    public Result save(@RequestBody @Valid SmsTemplateDto smsTemplate) {
        admSmsTemplateService.save(smsTemplate);
        return Result.success(null == smsTemplate.getId()? "新增短信模板成功" : "修改短信模板成功");
    }

    @ApiOperation("获取短信模板列表")
    @PostMapping("/getList")
    public Result getList(@RequestBody SmsTemplateListSearchDto search) {
        return Result.success("获取短信模板列表成功").data(admSmsTemplateService.getList(search));
    }

    @ApiOperation("获取短信模板详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "短信模板ID", required = true) Long id) {
        return Result.success("获取短信模板详情成功").data(PageUtil.row(admSmsTemplateService.getDetail(id)));
    }

    @ApiOperation("批量禁用或启用短信模板")
    @PostMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "短信模板状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "短信模板ID", required = true) List<Long> ids) {
        admSmsTemplateService.updateDisableBatchById(ids, status);
        return Result.success(status? "禁用短信模板成功" : "启用短信模板成功");
    }

}
